﻿@model XSTDZ.ERP.Application.DataContracts.ProductDeliveryBillDto
@{
    ViewBag.Title = " - 编辑产品发货";
}
@section header{
     <link href="@Url.Content("~/Content/Controls.css")" rel="stylesheet" type="text/css" />
     <link href="@Url.Content("~/Content/Form.css")" rel="stylesheet" type="text/css" />
}
<div class="wp100" id="divForm">

@using (Html.BeginForm())
{
    @Html.ValidationSummary(true)

    <table class="formtable">
    <thead>
        <tr>
            <th colspan="4">@* <h2>新增入库单</h2>*@
            <div id="toptoolbar"></div>
            </th>
        </tr>
    </thead>
    <tr>
       <input type="hidden" value="@ViewBag.WareHourseId" id="WareHourseId" name="WareHourseId" />
        <td class="title"> @Html.LabelFor(model => model.DeliveryNo)<b>*</b></td>
        <td> @Html.TextBoxFor(model => model.DeliveryNo, new { @class = "text disablebg", @readonly = "readonly" })
        @Html.ValidationMessageFor(model => model.DeliveryNo)
         <input type="hidden" value="@ViewBag.TempId" id="hidbillDetailId" name="hidbillDetailId"   />
          @Html.HiddenFor(model => model.Id)
           @Html.HiddenFor(model => model.BillState)
        </td>
        <td class="title">@Html.LabelFor(model => model.StorehouseID)<b>*</b></td>
        <td>  @Html.TextBoxFor(model => model.StorehouseName, new { @class = "text" })
          @Html.HiddenFor(model => model.StorehouseID)
            @Html.ValidationMessageFor(model => model.StorehouseID)
         </td>
  </tr>
       
         <tr>
           <td class="title">@Html.LabelFor(model => model.DeliveryorID)<b>*</b></td>
        <td> 
        @Html.TextBoxFor(model => model.DeliveryorName, new { @class = "text" })
         @Html.HiddenFor(model => model.DeliveryorID)
        @Html.ValidationMessageFor(model => model.DeliveryorID)
        </td>
        
       

         <td class="title"> @Html.LabelFor(model => model.DeliveryDate)<b>*</b></td>
        <td> @Html.TextBoxFor(model => model.DeliveryDate, new { @class = "text" })
         <input type="hidden" value="@Model.DeliveryDate" id="DeliveryDateVal" name="DeliveryDateVal" />
        @Html.ValidationMessageFor(model => model.DeliveryDate)
        </td>
  </tr> 
         <tr>
        <td class="title"> @Html.LabelFor(model => model.DeliveryID)<b>*</b></td>
        <td> @Html.TextBoxFor(model => model.DeliveryName, new { @class = "text" })
        @if (XSTDZ.ERP.Infrastructure.SystemConfig.XinChangCode != ViewBag.orgCode && ViewBag.orgCode != XSTDZ.ERP.Infrastructure.SystemConfig.LaoChangCode)
        {
        <a href="javascript:void(0);" onclick="javascript:selectOrg();" >选择</a>
        }
         @Html.HiddenFor(model => model.DeliveryID)
        @Html.ValidationMessageFor(model => model.DeliveryID)
        </td>

        <td class="title"> @Html.LabelFor(model => model.SenderID)<b>*</b></td>
        <td> @Html.TextBoxFor(model => model.SenderName, new { @class = "text" })
         @Html.HiddenFor(model => model.SenderID)
        @Html.ValidationMessageFor(model => model.SenderID)
        </td>
  </tr> 

    <tr>
        <td class="title"> @Html.LabelFor(model => model.Remarks)</td>
        <td> @Html.TextBoxFor(model => model.Remarks, new { @class = "text" })
        @Html.ValidationMessageFor(model => model.Remarks)
        </td>
        <td class="title"></td>
        <td>  
         </td>
  </tr> 
@*  @if (Model.BillState !=1)
  {*@
  <tr>
        <td  colspan="4" class="btnRow">
              <p class="divBtn">
                <input type="hidden" value="" name="hidProductBillItems" id="hidProductBillItems" />
               <input type="hidden" id="hidHttpRefeParent" name="hidHttpRefeParent" value="grid" />
            <input type="button" value="@XSTDZ.ERP.Infrastructure.SystemConfig.BtnSave"  class="BtnSubmit" id="submitBtn" name="submitBtn" />
             <input type="button" value="@XSTDZ.ERP.Infrastructure.SystemConfig.BtnSubmit"  class="BtnSubmit" id="btnSubmit" name="btnSubmit" />
        </p>
        </td>
    </tr>
@*  }*@
    </table>
    <input id="HidOrgCode" name="HidOrgCode" type="hidden" value="@ViewBag.orgCode" />
        <input id="HidEmptyGuid" name="HidEmptyGuid" type="hidden" value="@Guid.Empty" />
}
</div>
<div class="wp100">
<div id="ProductDeliveryItemsGrid" style="margin-top:20px" ></div>
</div>


<script type="text/javascript">
    $(document).ready(function () {
        //确认时间
        $("#DeliveryDate").ligerDateEditor({ showTime: true, format: "yyyy-MM-dd", labelWidth: 140, labelAlign: 'left' });
        $("#DeliveryDate").ligerGetDateEditorManager().setValue($("#DeliveryDateVal").val());
        //库房
        $("#StorehouseName").ligerPopupEdit({
            grid: getGridOptions(false),
            valueField: 'Id',
            textField: 'StorehouseName'
        });

        //发货人
        //        $("#DeliveryorName").ligerPopupEdit({
        //            grid: getUserGridOptions(false),
        //            valueField: 'Key',
        //            textField: 'Name'
        //        });
        getSelectUserGrid("DeliveryorName");
        //送货人
        getSelectUserGrid("SenderName");
        //        $("#SenderName").ligerPopupEdit({
        //            grid: getUserGridOptions(false),
        //            valueField: 'Key',
        //            textField: 'Name'
        //        });


        $("#submitBtn").unbind("click").bind("click", function () { getProductBillItemData(false); }); //保存
        $("#btnSubmit").unbind("click").bind("click", function () { getProductBillItemData(true); }); //提交
        initFormGridHeight("divForm", "ProductDeliveryItemsGrid");
    });

    //保存或提交都调用同一个方法
    //参数：isSave [是否为保存]
    function getProductBillItemData(isConfirm) {
        if ($("#BillState").val() == "1") { $.ligerDialog.success("已提交，不能再更新!"); }
        else {
            if (manager != null && manager != undefined) {
                if (!validateGridDetail(manager, "SenderCount")) { $.ligerDialog.success('明细数量不能小于0!'); return; }; //验证明细
                var data = manager.getData();
                $("#hidProductBillItems").val("").val(JSON.stringify(data));
                var btnText = ""; //
                if (!isConfirm) {
                    btnText = $("#submitBtn").val();
                    $("#submitBtn").val("").val("正在处理中...");
                }
                else {
                    btnText = $("#btnSubmit").val();
                    $("#btnSubmit").val("").val("正在处理中...");
                }
                //$.ajax({ type: "POST", url: "/ProductDelivery/Add", data: $("form").serialize(), // 要提交的表单
                $.ajax({ type: "POST", url: "/ProductDelivery/AddAndConfirm?isConfirm=" + isConfirm, data: $("form").serialize(), // 要提交的表单
                    success: function (msg) {
                        if (msg == "9") {
                            $.ligerDialog.success('操作成功!');
                            initligerGrid();
                            ajaxSubmitSuccess(); //公共类：提交成功后关闭当前窗口
                        }
                        else if (msg == "0") {
                            $.ligerDialog.success('数据不完整,请输入必填数据后再提交!');
                        }
                        else if (msg == "-3") {
                            $.ligerDialog.success('发货明细发货数量超过库存数量,操作失败!');
                        }
                        else if (msg != undefined && $.trim(msg).length > 10) {
                            $.ligerDialog.success('操作成功!');
                            $("#Id").val("").val(msg);
                            //initligerGrid();
                            ajaxSubmitSuccess(); //公共类：提交成功后关闭当前窗口
                        }
                        else {
                            $.ligerDialog.success('操作失败!');
                        }
                        if (!isConfirm) { $("#submitBtn").val("").val(btnText); } else { $("#btnSubmit").val("").val(btnText); }
                    }
                });
            }
        }
    }
    //收货单位
    function selectOrg() {
        var returnValue = window.showModalDialog('../Org/SelectOrgTree?selectType=1', window, "help:No;resizable:No;status:No;scroll:yes;dialogWidth=300px;dialogHeight=300px");
        $("#DeliveryName").val(returnValue[0]);
        $("#DeliveryID").val(returnValue[1]);
    }
</script>


<script type="text/javascript" src="@Url.Content("~/Scripts/ligerUI/js/plugins/ligerPopupEdit.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Scripts/ligerUI/js/plugins/ligerDateEditor.js")"></script>
@if (ViewBag.orgCode == XSTDZ.ERP.Infrastructure.SystemConfig.XinChangCode.ToString() || ViewBag.orgCode == XSTDZ.ERP.Infrastructure.SystemConfig.LaoChangCode.ToString())
{
<script type="text/javascript" src="@Url.Content("~/Content/js/ProductDelivery/FactoryAdd.js")"></script>
}
else
{ 
<script type="text/javascript" src="@Url.Content("~/Content/js/ProductDelivery/Add.js")"></script>
}
<script type="text/javascript" src="@Url.Content("~/Content/js/SelectData.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Content/js/formBase.js")"></script>